package cn.cvs.util;

import java.util.List;

/**
 * @Author: 邓必宏
 * @title:
 * @Demo:
 * @DateTime: 2023/8/21
 */
public class Page<T> {
    //总记录
    private int totalCount;
    //
    private List<T> list;
    //总页数
    private int totalPageCount;
    //当前页
    private int pageNo = 1;
    //页面大小
    private int pageSize = 10;

    @Override
    public String toString() {
        return "Page{" +
                "totalCount=" + totalCount +
                ", list=" + list +
                ", totalPageCount=" + totalPageCount +
                ", pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                '}';
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        if (totalCount > 0) {
            // 计算总页数
            totalPageCount = totalCount / pageSize;
            if (totalCount % pageSize != 0) {
                totalPageCount++;
            }
        }
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        if (pageNo > 0) {
            this.pageNo = pageNo;
        } else {
            this.pageNo = 1;
        }
        if (pageNo > totalPageCount) {
            this.pageNo = 1;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
}
